<!--
 * @Description: 消杀登记
 * @Author: XueTing
 * @Date: 2021-07-14 21:43:52
 * @LastEditors: luojie
 * @LastEditTime: 2021-08-16 01:07:41
-->
<template>
  <view class="xiaosha">
    <view class="top">
      <!-- <image v-if='thisType=="disinfect"' src="https://szgd-dev.tgovcloud.com/public/images/disinfect1.png" mode="widthFix"></image>
      <image v-else-if='thisType=="inspection"' src="https://szgd-dev.tgovcloud.com/public/images/inspection1.png" mode="widthFix"></image>
      <image v-else src="https://szgd-dev.tgovcloud.com/public/images/clean1.png" mode="widthFix"></image> -->
      <image :src="imageUrl" mode="widthFix"></image>
    </view>
    <view class="bottom">
      <view class="view-row" v-for="(item, index) in inputList" :key="index">
        <view class="view-row-title">{{ item.title }}</view>
        <view class="view-row-value">{{ item.value }}</view>
        </view>
    </view>
    <view class="btn" v-if="showBtn" @click="submit">提交</view>
  </view>
</template>

<script>
import { getData } from "@/api";
export default {
  data() {
    return {
      showBtn: true,
      inputList: [
        {
          title: "人员",
          value: '',
        },
        {
          title: "地点",
          value: ''
        },
        {
          title: "时间",
          value:''
        },
      ],
      goodsId:1003,
      QRCodeInfo:null,
      timer: '',
      thisType:'',
      imageUrl:'',
      thisTitle:'',
      imageList:[
        {
          url: "https://szgd-dev.tgovcloud.com/public/images/disinfect1.png",
          title: "消杀登记",
          type: "disinfect",
        },
        {
          url: "https://szgd-dev.tgovcloud.com/public/images/inspection1.png",
          title: "巡检登记",
          type: "inspection",
        },
        {
          url: "https://szgd-dev.tgovcloud.com/public/images/clean1.png",
          title: "保洁登记",
          type: "clean",
        },
        {
          url: "https://szgd-dev.tgovcloud.com/public/images/disinfect/banner-garbage.png",
          title: "垃圾管理监测",
          type: "WasteManagement",
        },
        {
          url: "https://szgd-dev.tgovcloud.com/public/images/disinfect/banner-sewage.png",
          title: "污水处理监测",
          type: "sewageDisposal",
        },
      ],
      requirementsObj:{
        disinfect: 2,
        inspection: 3,
        clean: 1,
        WasteManagement: 4,
        sewageDisposal: 5,
      }
    };
  },
  onLoad(e){
    console.log('onLoad===', e);
    if(e.from && e.from === 'recordList') {
      // 来源工作记录页面
      e = JSON.parse(decodeURIComponent(e.item));
      console.log('e====', e);
      uni.setNavigationBarTitle({
      　　title: e.title
      })
      this.thisTitle = e.title;
      this.thisType = e.type;
      this.showBtn = false;
      this.inputList.forEach(item => {
        switch(item.title){
          case '人员':
            item.value = e.name;
            break;
          case '地点':
            item.value = e.position;
            break;
          case '时间':
            item.value = e.timer;
            break;
        }
      })
      this.imageList.forEach(item=>{
        if (this.thisType == item.type) {
          this.imageUrl = item.url;
        }
      })
      if(e.registrationCard){
        this.inputList.push({
          title : '卡点编号',
          value : e.registrationCard
        })
      }
    } else {
      // 原来流程
      uni.setNavigationBarTitle({
      　　title: e.title
      })
      this.thisTitle = e.title;
      this.thisType = e.type;
      this.QRCodeInfo = uni.getStorageSync("QRCodeInfo");
      // console.log('this.QRCodeInfo===',this.QRCodeInfo)
      this.timer = this.getNowTime();
      let { name } = uni.getStorageSync("personalInfo");
      this.inputList.forEach(item => {
        switch(item.title){
          case '人员':
            item.value = name;
            break;
          case '地点':
            item.value = this.QRCodeInfo.position;
            break;
          case '时间':
            item.value = this.timer
            break;
        }
      });

      this.imageList.forEach(item=>{
        if (this.thisType == item.type) {
          this.imageUrl = item.url;
        }
      })
      if(this.QRCodeInfo.goodsId){
        this.inputList.push({
          title : '卡点编号',
          value : this.QRCodeInfo.registrationCard || '-'
        })
      }
    }
  },
  methods: {
    submit() {
      let { 
        goodsId,
        isolationHotelId,
        houseId,
        position
        } = this.QRCodeInfo;
      let personInfo = uni.getStorageSync("personalInfo");
      if(goodsId){
        let params = {
          goodsId,
          operationWay:1,
          registrant:personInfo.name,
          registerTime:this.timer,
          isolationHotelId,
          businessOperator:personInfo.name,
          businessTime: this.timer,
          // requirementsDetailType: this.thisType == 'inspection'?3:this.thisType=='disinfect'?2:this.thisType=='clean'?1:'',
          requirementsDetailType: this.requirementsObj[this.thisType],
          businessOperatorSign:personInfo.uid,
          businessPosition: position
        }
        // 房间：用/goods/houses/clearn房间保洁接口；物品：用/goods物品保洁接口
        // const url=!houseId?'goods':'houseClean'
        // 物品消杀
        getData('goods','post',params).then((res)=>{
          uni.navigateTo({
            url: `./submit?title=${this.thisTitle}`,
          });
        })
      }else{
        // 保洁;消杀disinfect
        let params = this.thisType=='disinfect'? {
          xsPerson:personInfo.name,
          xsTime:this.timer,
          operationWay:1,
          houseId:isolationHotelId || houseId
        }:{
          "bjPerson": personInfo.name,
          "bjTime": this.timer,
          "bjqkInfoId": "",
          "houseId": houseId,
          "operationWay": 1,
          "registrant": personInfo.name,
          "remark": ""
        }

        const apiUrl=this.thisType=='disinfect'?'disinfection':'houseClean';
        getData(apiUrl,'post',params).then((res)=>{
          uni.navigateTo({
            url: `./submit`,
          });
        })
      }
    },

     getNowTime: function () {
      let dateTime
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      mm = mm<10?'0'+mm:mm;
      dd = dd<10?'0'+dd:dd;
      hh = hh<10?'0'+hh:hh;
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
        :
        new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
        :
        new Date().getSeconds()
      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      console.log(dateTime)
      return dateTime
    },
  },
  mounted(){
    // this.getdislist(this.goodsId);
  }
};
</script>

<style lang="scss" scoped>
.xiaosha {
  width: 100%;
  padding: 40rpx;
  box-sizing: border-box;
  .view-row{
    display:flex;
    justify-content: space-between;
    margin-bottom:50rpx;
    &-title{
      flex: 0 0 140rpx;
    }
    &-value{
      margin-left: 30rpx;
      // flex: 1;
    }
  }
  .top {
    height: 300rpx;
    //   padding-left: 16rpx;
    image {
      width: 670rpx;
    }
  }
  .bottom {
    box-sizing: border-box;
    .input {
      width: 100%;
      display: flex;
      height: 96rpx;
      .title {
        width: 20%;
        padding: 27rpx 0;
      }
      .uni-input {
        width: 80%;
        text-align: right;
        padding: 24rpx 0 24rpx 0;
      }
    }
  }
  .btn {
    width: 100%;
    height: 94rpx;
    background: #2c9af1;
    border-radius: 16px;
    text-align: center;
    font-size: 34rpx;
    font-weight: 500;
    line-height: 48px;
    color: #ffffff;
    margin-top: 50rpx;
  }
}
</style>